/**
 * Created by Administrator on 2016/8/1.
 */
$(document).ready(function(){
    var $width = $(window).width();
    var $height = $(window).height();
    $("section p:first-child span").text("￥"+sessionStorage.kitingMoney);
    $("button").css("top",$height-180);
    var ceilPhone = $("#ceilPhone").val();
    var user_token =  sessionStorage.user_token;
    var u_id = sessionStorage.u_id;
    var session_id =  sessionStorage.session_id;
    $.post(commonval+"/cash_recent_info",{
        u_id:u_id,
        device:"wap",
        user_token:user_token,
        session_id:session_id
    },function(data) {
        if(data.status == 1){
            $("#ceilPhone").val(data.data.alipay);
            $("#userName").val(data.data.alipay_name);
        }else{

        }
    });
    $("header img:first-child").click(function(){
        //history.go(-1);
    })
    $("#button1").click(function(){
        var kitingMoney = $("#kitingMoney").val();
        if(kitingMoney<5){
            createWindow("提现金额不能少于5元");
        }else if(kitingMoney>sessionStorage.kitingMoney){
            createWindow("提现金额不能超过余额");
        } else{
            $("section p:first-child").css("display","none");
            $("section p:nth-child(2)").css("display","block");
            $("#button1").css("display","none");
            $("#button2").css("display","block");
            $("section:nth-child(4)").css("display","none");
            $("section:nth-child(5)").css("display","block");
            $("section:nth-child(6)").css("display","block");
            $("header img:first-child").unbind("click");
            $("header img:first-child").click(function(){
                $("section p:first-child").css("display","block");
                $("section p:nth-child(2)").css("display","none");
                $("#button1").css("display","block");
                $("#button2").css("display","none");
                $("section:nth-child(4)").css("display","block");
                $("section:nth-child(5)").css("display","none");
                $("section:nth-child(6)").css("display","none");
                $("header img:first-child").unbind("click");
                $("header img:first-child").click(function(){
                    history.go(-1);
                })
            })
        }
    })
    $("#button2").click(function(){
        var ceilPhone = $("#ceilPhone").val();
        var userName = $("#userName").val();
        if(ceilPhone ==''){
            createWindow("支付宝账号不能为空");
        }else{
            if(userName ==''){
                createWindow("真实姓名不能为空");
            }else{
                $("section p:nth-child(2)").css("display","none");
                $("section p:nth-child(3)").css("display","block");
                $("#button2").css("display","none");
                $("#button3").css("display","block");
                $("section:nth-child(5)").css("display","none");
                $("section:nth-child(6)").css("display","none");
                $("section:nth-child(7)").css("display","block");
                $("header img:first-child").unbind("click");
                $("header img:first-child").click(function(){
                    $("section p:nth-child(2)").css("display","block");
                    $("section p:nth-child(3)").css("display","none");
                    $("#button2").css("display","block");
                    $("#button3").css("display","none");
                    $("section:nth-child(5)").css("display","block");
                    $("section:nth-child(6)").css("display","block");
                    $("section:nth-child(7)").css("display","none");
                    $("header img:first-child").unbind("click");
                    $("header img:first-child").click(function(){
                        $("section p:first-child").css("display","block");
                        $("section p:nth-child(2)").css("display","none");
                        $("#button1").css("display","block");
                        $("#button2").css("display","none");
                        $("section:nth-child(4)").css("display","block");
                        $("section:nth-child(5)").css("display","none");
                        $("section:nth-child(6)").css("display","none");
                        $("header img:first-child").unbind("click");
                        $("header img:first-child").click(function(){
                            history.go(-1);
                        })
                    })
                })
            }
        }
    })
    $("#button3").click(function(){
        var ceilPhone = $("#ceilPhone").val();
        var userName = $("#userName").val();
        var kitingMoney = $("#kitingMoney").val();
        var password = $("#password").val();
        if(password ==''){
            createWindow("账户密码不能为空");
        }else{
            var user_token =  sessionStorage.user_token;
            var u_id = sessionStorage.u_id;
            var session_id =  sessionStorage.session_id;
            $.post(commonval+"/cash",{
                u_id:u_id,
                device:"wap",
                user_token:user_token,
                session_id:session_id,
                alipay:ceilPhone,
                money:kitingMoney,
                alipay_name:userName,
                password:password
            },function(data) {
                if(data.status == 1){
                    location.href="../html/kitingSuccess.html";
                    sessionStorage.kitingMoney = kitingMoney;
                }else{
                    createWindow("操作失败");
                }
            });

        }
    })

});

function createWindow(msg) {
    var window =$("<section class='showMsg'></section>");
    var show = "<p>"+msg+"</p>";
    window.append(show);
    $("body").append(window);
    setTimeout("$('.showMsg').remove()",5000);
}